package com.sanben.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sanben.common.util.BeanCopyUtils;
import com.sanben.company.data.dto.CompanyTeamCaseDto;
import com.sanben.company.data.req.CompanyTeamCaseReq;
import com.sanben.company.data.vo.CompanyTeamCaseVo;
import com.sanben.company.entity.CompanyTeamCase;
import com.sanben.company.mapper.CompanyTeamCaseMapper;
import com.sanben.company.service.ICompanyTeamCaseService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author cyh
 * @description: 公司团队案例表 服务实现类
 * @date: 2020-08-11
 */
@Service
public class CompanyTeamCaseServiceImpl extends ServiceImpl<CompanyTeamCaseMapper,CompanyTeamCase> implements ICompanyTeamCaseService {

    @Override
    public IPage<CompanyTeamCaseVo> page(CompanyTeamCaseReq req) {
        Page<CompanyTeamCaseVo> page = new Page<>(req.getPageNum(), req.getPageSize());
        page.setRecords(this.baseMapper.page(page, req));
        return page;
    }

    @Override
    public List<CompanyTeamCase> getHomeList() {
        LambdaQueryWrapper<CompanyTeamCase> lambdaQuery = new LambdaQueryWrapper<>();
        lambdaQuery.orderByDesc(CompanyTeamCase::getSort)
                .last("limit 5");
        return this.list(lambdaQuery);
    }

    @Override
    public Boolean save(CompanyTeamCaseDto dto) {
        return this.save(BeanCopyUtils.copy(dto,CompanyTeamCase.class));
    }

    @Override
    public Boolean updateById(CompanyTeamCaseDto dto) {
        return this.updateById(BeanCopyUtils.copy(dto,CompanyTeamCase.class));
    }


    @Override
    public Boolean deleteLogic(List<Integer> toIntList) {
        return  this.removeByIds(toIntList);
    }

    @Override
    public CompanyTeamCase detail(Integer id) {
        return this.getById(id);
    }
}
